home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- /*
- * Kurt Akeley
- * 22 April 1991
- *
- * Hacked version of /jake/att/usr/src/cmd/demo/src/flip/flipobj.c
- */
-
- #include <math.h>
- #include <stdio.h>
- #include <gl/gl.h>
- #include <gl/device.h>
-
- #include <flip.h>
-
- flipobj
- *readflipobj(name)
- char *name;
- {
- FILE *inf;
- flipobj *obj;
- int i, j;
- int nlongs;
- int magic;
- int *ip;
- char s[200];
-
- inf = fopen(name,"r");
- if(!inf) {
- sprintf(s,"%s%s",MODELDIR,name);
- inf = fopen(s,"r");
- }
- if(!inf) {
- fprintf(stderr,"readfast: can't open input file %s\n",name);
- fprintf(stderr," can't open input file %s\n",s);
- exit(1);
- }
- fread(&magic,sizeof(int),1,inf);
- if(magic != FASTMAGIC) {
- fprintf(stderr,"readfast: bad magic in object file\n");
- fclose(inf);
- exit(1);
- }
- obj = (flipobj *)malloc(sizeof(flipobj));
- fread(&obj->npoints,sizeof(int),1,inf);
- /*** IGNORE COLORS FIELD ***/
- fread(&magic,sizeof(int),1,inf);
-
- /*
- * Insure that the data is quad-word aligned and begins on a page
- * boundary. This shields us from the performance loss which occurs
- * whenever we try to fetch data which straddles a page boundary (the OS
- * has to map in the next virtual page and re-start the DMA transfer).
- */
- nlongs = 8 * obj->npoints;
- obj->data = (float *) malloc(nlongs*sizeof(int) + 4096);
- obj->data = (float *) (((int)(obj->data)) + 0xfff);
- obj->data = (float *) (((int)(obj->data)) & 0xfffff000);
-
- for (i = 0, ip = (int *)obj->data; i < nlongs/4; i++, ip += 4)
- fread(ip, 3 * sizeof(int), 1, inf);
- fclose(inf);
-
- return obj;
- }
-
- void
- drawflipobj(obj)
- flipobj *obj;
- {
- register float *p,*end;
-
- p = obj->data;
- end = p + 8 * obj->npoints;
-
- while ( p < end) {
- bgnpolygon();
- n3f(p);
- v3f(p+4);
- n3f(p+8);
- v3f(p+12);
- n3f(p+16);
- v3f(p+20);
- n3f(p+24);
- v3f(p+28);
- endpolygon();
- p += 32;
- }
- }
-
-
- /*
- * objmaxpoint
- *
- * find the vertex farthest from the origin,
- * so we can set the near and far clipping planes tightly.
- */
-
- #define MAXVERT(v) if ( (len = sqrt( (*(v)) * (*(v)) + \
- (*(v+1)) * (*(v+1)) + \
- (*(v+2)) * (*(v+2)) )) > max) \
- max = len;
-
- float
- objmaxpoint(obj)
- flipobj *obj;
- {
- register float *p, *end;
- register int npolys;
- register float len;
- register float max = 0.0;
-
- p = obj->data;
-
- end = p + 8 * obj->npoints;
- while ( p < end) {
- MAXVERT(p+4);
- MAXVERT(p+12);
- MAXVERT(p+20);
- MAXVERT(p+28);
- p += 32;
- }
-
- return max;
- }
-